<include file="__THEME__/header" />
<link href="../Public/notify.css" rel="stylesheet" type="text/css" />
<script>
	var old_button =  "";
	var sending = false;
    function agreeFri(fuid, nid){
        Win({
            message: '__APP__/Friend/isAdd/uid/' + fuid + '/nid/' + nid + '/t/agree',
            width: 392,
            height: 220,
            title: '加为好友',
            handler: function(){
                ymPrompt.close();
            },
            autoClose: false,
            iframe: true,
            allowRightMenu: true
        });
    }
    
    function ignoreFri(uid, nid){
        Confirm({
            message: '确认忽略这条好友请求?',
            handler: function(tp){
                if (tp == 'ok') {
                    $.post(APP + "/Friend/ignoreFriend", {
                        nid: nid,
                        uid: uid
                    }, function(txt){
                        if (txt == 1) {
                            Alert("忽略成功!");
                            setTimeout(function(){
                                parent.ymPrompt.close();
                            }, 1500);
                            location.reload();
                        }
                        else {
                            Alert("忽略失败!");
                        }
                    });
                }
                if (tp == 'cancel') {
                    ymPrompt.close();
                }
                if (tp == 'close') {
                    ymPrompt.close();
                }
            }
        });
    }
    
    function set_group(fuid, nid){
        Win({
            message: '__APP__/Friend/setGroup/fuid/' + fuid + '/nid/' + nid,
            width: 392,
            height: 220,
            title: '加为好友',
            handler: function(){
                ymPrompt.close();
            },
            autoClose: false,
            iframe: true,
            allowRightMenu: true
        });
    }
    
    //删除某条动态
    function del_notify(id){
        $.post(URL + "/del_notify", {
            id: id
        }, function(txt){
            if (txt == 1) {
                $("#notify_" + id).hide("slow");
            }
            else {
                Error("删除失败!");
            }
        });
    }
    
    function replayButton(quietly, toId, type, appid){
		if (sending) {
			Confirm({
				message: '是否丢弃前面所写的评论?',
				handler: function(tp){
					if (tp == 'ok') {
						showContent(quietly, toId, type, appid);
					}
					if (tp == 'cancel') {
						ymPrompt.close();
					}
					if (tp == 'close') {
						ymPrompt.close();
					}
				}
			});
		}else{
			showContent(quietly, toId, type, appid);
		}
	}
	
	function showContent(quietly, toId, type, appid){
		$('.pin_04').show();
		$('#replay').remove();
        var html = '			<div id="replay">\
        	                            	<div class="pin_04">\
        	                                	<textarea id="content" cols="" rows="5" class="Text" style="width: 400px;"></textarea>\
        	                            	</div>\
        	                            	<div class="pin_04">\
        	                                <input type="button" id="replayButton" value="回 复" class="btn_b mr10"/><input type="button" id="quxiao" value="取 消" class="btn_w"/>\
        	                            	</div>\
        								</div>';
        $("#"+type+ toId).before(html);
		$('#replayButton').click(function(){
			ReplayComment($('#replayButton'),quietly, toId, type, appid);
		});
		$('#quxiao').click(function(){
			quxiao();
		});
		$('#content').blur(function(){
			if ($('content').val() != "") {
				sending = true;
			}else{
				sending = false;
			};
		});
		old_button = $('#comment'+toId).clone();
		$('#comment'+toId).hide();
	}
	
	function quxiao(){
		$('.pin_04').show();
		$('#replay').remove();
		sending = false;
	}
	
	
	function subComment( vo ){
	 var result = '  <div id="'+vo.type+vo.id+'">\
                                    <div class="pin_01">\
                                        <div class="pin_02"><a href="'+APP+'/space/'+vo.uid+'">\
                                            <img src="'+vo.face+'" width="30" height="30" ></a>\
                                        </div>\
                                        <div class="pin_03">\
                                            <span>'+vo.name+'回复：</span>\
                                            '+vo.comment+'<span>'+vo.cTime+'</span>\
                                        </div>\
                                    </div>\
                                    <div class="c">\
                                    </div>\
                                </div>';
	  return result;
	}
    
	function deleteCommentCount( appid ){
	    //计数
	    $.post(APP+'/Index/deleteSuccess',{
	        id:appid
	    },function(result){
	        $('#commentCount').text(result);
	    });
	}
	function commentSuccess(json){
	    //计数
	    $.post(APP+'/Index/commentSuccess',{
	        data:json
	    },function(result){
	        $('#commentCount').text(result);
	    });
	}
    /**
     * addComment
     * 添加评论
     * @access public
     * @return void
     */
    function ReplayComment(_this, quietly, toId, type, appid){
        var Abottom = _this.val();
        var content = $('#content').val();
        _this.val('loadding...');
        _this.attr('disabled', true);
        
        //检查字数
        if (JHshStrLen(content) >= 4000) {
            Alert("最多2000个中文字符");
            _this.attr('disabled', false);
            _this.val(Abottom);
            return
        }
        if (content.length < 3) {
            Alert("最少10个字符");
            _this.removeAttr('disabled');
            _this.val(Abottom);
            return
        }
        $.post(APP + "/Comment/doAddComment", {
            comment: content,
            type: type,
            appid: appid,
            toId: toId,
            quietly: quietly
        }, function(txt){
            if (txt != -1) {
                var a = new Array();
                JSON.parse(txt, function(key, value){
                    a[key] = value;
                });
                $('#replay').before(subComment(a));
                $('#content').val("");
				$('#replay').remove();

                //发送动态回调函数
                try {
                    commentSuccess(txt);
                } 
                catch (err) {
                
                }
            }
            else {
                Alert('添加失败，请稍后再试');

            }
			_this.val(Abottom);
            _this.removeAttr('disabled');
			$('#comment'+toId).show();
			sending = false;
        });
    }
</script>
<div class="content">
    <!-- 内容 begin  --><include file="__THEME__/apps" />
    <div class="main">
        <!-- 画布 begin  -->
        <div class=page_title>
            <!-- page_title begin --><h2><img src="../Public/images/computer.gif" />消息</h2>
            <div class="c">
            </div>
        </div>
        <!-- page_title end -->
        <div class="tab-menu">
            <!-- 切换标签 begin  -->
            <ul>
                <li>
                    <a href="__URL__/inbox"><span>收件箱</span></a>
                </li>
                <li>
                    <a href="__URL__/send"><span>发件箱</span></a>
                </li>
                <li>
                    <a href="__URL__/index" class="on"><span>通知</span></a>
                </li>
                <li>
                    <a href="__URL__/write"><span>
                            <div class="ico_add">
                                &nbsp;
                            </div>写短消息
                        </span></a>
                </li>
            </ul>
        </div>
        <!-- 切换标签 end  -->
        <div class="MenuSub">
            <a
                <php>
                    if(!$_GET['t']){echo 'class="on"';}
                </php>
                href="__URL__">全部通知
            </a>
            <a
                <php>
                    if($_GET['t']=='sys'){echo 'class="on"';}
                </php>
                href="__URL__/index/t/sys">系统通知
            </a>
            <a
                <php>
                    if($_GET['t']=='fri'){echo 'class="on"';}
                </php>
                href="__URL__/index/t/fri">好友请求
            </a>
            <a href="#">应用通知</a>
        </div>
        <div class="BlogBox">
            <div class="sidebar pt10">
                <div class="FSort">
                    <div class="tit">
                        通知类别
                    </div>
                    <ul>
                        <li
                            <php>
                                if(!$_GET['t']){echo 'class="on"';}
                            </php>><a href="__URL__">全部通知</a>
                        </li>
                        <li
                            <php>
                                if($_GET['t']=='sys'){echo 'class="on"';}
                            </php>><a href="__URL__/index/t/sys">系统通知</a>
                        </li>
                        <li
                            <php>
                                if($_GET['t']=='fri'){echo 'class="on"';}
                            </php>
                            ><a href="__URL__/index/t/fri">好友请求</a>
                        </li>
                        <li>
                            <a href="#">应用通知</a>
                        </li>
                    </ul>
                    <div class="btm">
                    </div>
                </div>
            </div>
            <div class="MList" style="width:600px;">
                <!-- 通知列表 begin  -->
                <ul>
                    <volist name="notifys" id="notify">
                        <li class="btmlineD" id="notify_{$notify.id}">
                            <div class="left" style="width:10%">
                                <span class="headpic50">
                                    <php>
                                        if($notify['authorid']!=0){
                                    </php>
                                    <a href="__APP__/space/{$notify.authorid}" class="tips" rel="__TS__/Index/userInfo/uid/{$notify['authorid']}"><img src="{$notify.authorid|getUserFace}" alt="{$notify.author}" /></a>
                                    <php>
                                        }else{
                                    </php>
                                    <img src="{$notify.authorid|getUserFace}" alt="{$notify.author}" />
                                    <php>
                                        }
                                    </php>
                                </span>
                            </div>
                            <div class="left" style="width:90%">
                                <h3>
                                    <div class="right alR">
                                        <div class="left">
                                            <em>{$notify.cTime|friendlyDate='full'}</em>
                                        </div>
                                        <div class="left">
                                            <a href="javascript:del_notify({$notify.id})" class="del" style=" margin:4px 0 0 0;">删除</a>
                                        </div>
                                    </div>
                                    <strong>{$notify.type_cn}：</strong></h3>
                                <div>
                                    <div class="right alR">
                                        <!-- TIP -->
                                        <php>
                                            if($notify["new"]>=2 &&  $notify["deal"]){
                                            echo '
                                            <div class="tip">
                                                ';
                                                $deal = explode("|",$notify["deal"]);
                                                echo  ($notify["new"] == 2)?$deal[0]:$deal[1];
                                                echo '
                                            </div>';
                                            }
                                        </php>
                                        <!-- TIP END -->
                                    </div>
                                    <p>
                                        {$notify.title}
                                    </p>
                                    <p>
                                        {$notify.body}
                                    </p>
                                </div>
                                <!-- URL -->
                                <div class="lh35">
                                    <lt name="notify.new" value="2">
                                        <php>
                                            if($notify['type'] == "add_friend"){
                                        </php>
                                        <a href="javascript:agreeFri({$notify.url},{$notify.id});">同意</a>
                                        | <a href="javascript:ignoreFri({$notify.url},{$notify.id});">忽略</a>
                                        <php>
                                            }elseif($notify['type'] == "agree_friend"){
                                        </php>
                                        <a href="javascript:set_group({$notify.authorid},{$notify.id})">设置好友分组</a>
                                        <php>
                                            }elseif($notify["url"]){
                                        </php>
                                        <a href="{$notify.url}">去看看</a>
                                        <php>
                                            }
                                        </php>
                                    </lt>
                                </div>
                                <!-- URL END -->
                            </div>
                            <php>
                                if($notify['child']){
                            </php>
                            <sublist name="notify.child" id="subComment">
                                <div id="{$notify.ctype}{$subComment.id}">
                                    <div class="pin_01">
                                        <div class="pin_02">
                                            <a href="__TS__/space/{$subComment.uid}"><img src="{$subComment.face}" width="30" height="30" /></a>
                                        </div>
                                        <div class="pin_03">
                                            <span>{$subComment.name}回复：</span>
                                            {$subComment.comment}<span>{$subComment.cTime}</span>
                                        </div>
                                    </div>
                                    <div class="c">
                                    </div>
                                </div>
                            </sublist>

                            <php>
                                }
                            </php>
							<php>if(isset($notify['child'])){</php>
							 <div id="{$notify.ctype}{$notify.toId}">
                            </div>
                            <div class="pin_04" id="comment{$notify.toId}">
                                <input type="submit" onclick="replayButton({$notify.quietly},{$notify.toId},'{$notify.ctype}',{$notify.appid})" value="回复" class="btn_b mr10"/>
                            </div>
							<php>}</php>
                        </li>
                    </volist>
                </ul>
                <php>
                    echo page($total_page);
                </php>
            </div>
            <!-- 通知列表 end  -->
        </div>
    </div>
    <!-- 画布 end  -->
    <div class="c">
    </div>
</div>
<!-- 内容 end --><include file="__THEME__/footer" />